package net.glease.PickID;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Students {
	public List<Integer> full =new ArrayList<Integer>();
	public int currunt;
	
	public Students(){
		currunt=-1;
	}
	
	public void load(String config) throws IOException {
		System.out.println(config);
		File file = new File(config);
        if(!file.exists()||file.isDirectory())
            throw new FileNotFoundException();

        BufferedReader br=new BufferedReader(new FileReader(file));
        Integer temp=null;
        temp=Integer.parseInt(br.readLine());
        while(temp!=null){
            if(temp!=32)
        		full.add(temp);
            try{temp=Integer.parseInt(br.readLine());}catch(Exception e){}
        }
        br.close();
	}
	
	@Override
	public String toString(){
		return String.valueOf(currunt);
	}
	
	public void getRandomNext(){
		try{
			currunt = full.get((int)(Math.ceil(Math.random()*full.size())));
		}catch(Exception e){
			e.printStackTrace();
		}
        File file=new File(PickID.HIST_FILE);
        if(!file.exists())
			try {
				file.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
        FileOutputStream out = null;
		try {
			out = new FileOutputStream(file,true);
		} catch (Exception e) {
		}        
        StringBuffer sb=new StringBuffer();
        sb.append(String.valueOf(currunt));
        try {
			out.write(sb.toString().getBytes("utf-8"));
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
